#ifndef ROBOTGLCONTROLLER_H
#define ROBOTGLCONTROLLER_H

#include <QObject>
#include <QList>
#include <QDebug>
#include <QMouseEvent>

#include "robot.h"

#define MALLOC_COMPONENT (GUIComponent*)malloc(sizeof(GUIComponent))

class OpenGLDisplay;

/**
 * @brief Parent class for all controllers associated with an OpenGLDisplay.
 *
 * The controller is responsible for interpreting the user input and
 * manipulating the robot.  This class is used with an openGL display, so
 * it needs to handle the selection and manipulation of various "components"
 * of the robot wireframe.  A "GUIComponent" is an object on the screen
 * that can be clicked on manipulated, such as the forearm of Troy.
 *
 * To subclass RobotGLController, implement the pure virtual functions
 * mousePress(), mouseRelease(), mouseMove() to handle mouse input,
 * componentPicked() to handle OpenGL picking (using the name stack),
 * and initComponents() to create the internal data structure associated
 * with the components in the display.
*/
class RobotGLController : public QObject
{
    Q_OBJECT

public:
    explicit RobotGLController(QObject* parent = 0);

    //Functions to establish the connections between the controller,
    //view, and model
    virtual void loadModel(Robot* robot);
    virtual void loadView(OpenGLDisplay* view);

    void allowEditing(bool allowed);

    //Pure virtual functions that need to be overridden by subclasses
    //to deal with mouse behaviors (which are passed along from the view)
    virtual void mousePressEvent(QMouseEvent *event) = 0;
    virtual void mouseReleaseEvent(QMouseEvent *event) = 0;
    virtual void mouseMoveEvent(QMouseEvent* event) = 0;
    //This function is called by the view when the mouse is clicked
    //on an object in the openGL scene (it is called the "picked" object)
    virtual void componentPicked(NameGroup names) = 0;
    //This function is called by the view when there was nothing picked
    virtual void noPick() = 0;

protected:
    //The controller maintains connections to the other parts of the
    //MVC architecture
    Robot* _model;
    OpenGLDisplay* _view;

    bool _editingAllowed;

signals:
    void editingFinished();
};

#endif // ROBOTGLCONTROLLER_H
